<template>
  <div class="update-name">
    <!-- 导航栏 -->
    <van-nav-bar
      title="设置昵称"
      left-text="取消"
      right-text="完成"
      @click-left="$emit('close')"
      @click-right="onConfirm"
    />
    <!-- /导航栏 -->
    <!-- 输入框 -->
    <div class="field-wrap">
      <van-field
        v-model.trim="name"
        rows="2"
        autosize
        type="textarea"
        maxlength="7"
        placeholder="请输入昵称"
        show-word-limit
      />
    </div>
    <!-- /输入框 -->
  </div>
</template>

<script>
import {updateUserProfileApi} from  '@/api'
export default {
  name: "",
  props:['nickname'],
  data(){
      return {
          name:''
      }
  },
  created(){
      this.name=this.nickname
  },
  methods: {
    async onConfirm() {
        /* 
        + 获取表单值
        + 发送请求
        + 成功后 关闭对话框 + 重新获取数据
        
        */

       const  {data:res}=await updateUserProfileApi({
           name:this.name
       })

       this.$emit('namesuccess')



    }
  }
};
</script>
<style lang="less" scoped></style>
